const request = ({url, baseUrl = 'http://localhost:8002', method = 'get', headerConfig = {}, data = {}}) => {
	// url: '/login',发请求需要完成
	
	const token = uni.getStorageSync('token')
	
	const header = token ? {token,...headerConfig} : headerConfig
	
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseUrl + url,
			method,
			header,
			data,
			success(res) {
				if(res.statusCode === 200) {
					console.log('使用了新的request方法')
					resolve(res.data)
				} else if(res.statusCode===401) {
					uni.showToast({
						title:'登录失效，请重新登录'
					})
					uni.navigateTo({
						url:'/pages/Login/Login'
					})
				} else {
					uni.showToast({
						title:'服务器错误'
					})
					reject('服务器错误')
				}
			},
			fail(err) {
				reject(err)
			}
		})
	})
}
export default request

// 